
(*
	invoked when files are dropped onto the app's icon
*)
on open (arg)

	repeat with i in arg
		my importtunes(i)
	end repeat
	
end open

(*
	invoked when the app is double-clicked
*)
on run

	set myfile to choose file of type {"TEXT"} with prompt "Choose the yamltunes file(s) you wish to import" with multiple selections allowed without invisibles
	my importtunes(myfile)

end run

(*
	the workhorse
*)
on importtunes(yamltunes)

	set mypath to (POSIX path of (path to me)) & "Contents/Resources/ruby/"
	if ((yamltunes as string) ends with ".yamltunes") then
		set myscript to "ruby " & mypath & "yamltuneimporter.rb " & (POSIX path of yamltunes as string)
		do shell script myscript
	else
		display alert "Error" message ((yamltunes as string) & " is not a yamltunes file.")
	end if
end